#!/usr/bin/perl
use strict;
use warnings;
use 5.010;  # 声明支持state关键字的Perl版本
use utf8;
binmode(STDOUT, ":encoding(utf8)");

# 输出Hello World
print "Hello, World\n";
print "你好，世界\n";

# 变量
## 1、标量
my $name = "张三";
print "我是$name\n";

my $money = 100000000;
print "我有$money"."元\n";

## 2、数组
my @number = (1, "2", 3, "4");
print $number[0]."\n";
print $number[1]."\n";

for (my $i = 0; $i < 4; $i++) {
    print $number[$i]."\n";
}

foreach my $num (@number) {
    print $num."\n";
}

## 3、哈希
my %age = ("Alice" => 30, "Bob" => 25);
print $age{"Alice"}."\n";
print $age{"Bob"}."\n";

# 方法
# 关键字state
sub Subroutine{
    state $Scalar = 2;            #持久局部变量, 作用域为子程序内部
    $Scalar += 1;
    print $Scalar;
}

&Subroutine;                     #输出3
&Subroutine;                     #输出4

